﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Reflection;

namespace Deloitte.Data
{
    public class DataColumnToObjectPropertyMap<T>
    {

        public DataColumnToObjectPropertyMap(string dataRowColumnName, string propertyName)
        {
            this.DataRowColumnName = dataRowColumnName;
            this.PropertyName = propertyName;
        }
        private string _dataRowColumnName;

        public string DataRowColumnName
        {
            get { return _dataRowColumnName; }
            set { _dataRowColumnName = value; }
        }

        private string _propertyName;

        public string PropertyName
        {
            get { return _propertyName; }
            set { _propertyName = value; }
        }

        public bool IsValid(DataTable table, T myObject)
        {
            PropertyInfo info;
            try
            {
                info = (typeof(T).GetProperty(this.PropertyName));
            }
            catch (Exception) { return false; }
            if (!table.Columns.Contains(this.DataRowColumnName)) return false;
            return true;
        }
    }
}
